﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CoreProject.IRepository;
using CoreProject.Model;
using Microsoft.EntityFrameworkCore;

namespace CoreProject.Repository
{
    public class DeptRepository : BaseRepository<Department>, IDeptRepository
    {
        private readonly EFDbContext _dbContext;

        public DeptRepository(EFDbContext dbContext) : base(dbContext)
        {
            this._dbContext = dbContext;
        }

        public async Task<(List<Department> list, int count)> GetDeptBypage(string name, int page, int size)
        {
            var data =await _dbContext.Departments.ToListAsync();
            if (!string.IsNullOrWhiteSpace(name))
            {
                data = data.Where(n => n.DeptName.Contains(name)).ToList();
            }
            int count = data.Count();
            var pagelist = data.OrderBy(n => n.DeptId).Skip((page - 1) * size).Take(size);
            return (pagelist.ToList(), count);
        }
    }
}
